#include "MenuButton.h"
#include "MainGame.h"
#include "2d\CCMenuItem.h"
#include "2d\CCActionInterval.h"
USING_NS_CC;
MenuButton::MenuButton()
{
}


MenuButton::~MenuButton()
{
}

void MenuButton::startAction(Object* pSender)
{
	if (mTestOnlyClick == false){
		auto action0 = ScaleTo::create(0.1f, 0.9f, 1.1f);
		auto action1 = ScaleTo::create(0.1f, 1.1f, 0.9f);
		auto action2 = ScaleTo::create(0.1f, 1.f, 1.f);
		auto sequence = Sequence::create(action0, action1, action2, CallFunc::create([this](){
			mDoneAction = true;
		}), NULL);
		mMenuItem->runAction(sequence);
		mTestOnlyClick = true;
	}
}


void MenuButton::init(std::string name, Layer* target, BUTTON_ID id)
{
	mId = id;
	mTestOnlyClick = false;
	mMenuItem = MenuItemSprite::create(
		Sprite::createWithSpriteFrameName(name),
		NULL, NULL,
		this,
		menu_selector(MenuButton::startAction));
	Menu* mMenu = Menu::create(mMenuItem, NULL);
	target->addChild(mMenu);
}
